package com.xiaofeng.springboot.controller;

import javax.annotation.Resource;

import org.json.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.xiaofeng.springboot.aop.RestfulApi;
import com.xiaofeng.springboot.commons.ResultResponse;
import com.xiaofeng.springboot.service.MessageService;

/**
 * 首页
 * @author chenzf
 * @date 2016年6月23日上午11:41:56
 */
@Controller
@RequestMapping("/")
@SuppressWarnings("static-method")
public class IndexController {

	@Resource
	private MessageService messageService;

	@ResponseBody
	@RequestMapping
	@RestfulApi
	public String index() {
		JSONObject returnJson = new JSONObject();
		//		returnJson.append("param", messageService.getName());
		//		returnJson.append("code", 0);
		System.out.println(messageService.getName());
		return returnJson.toString();
	}

	@ResponseBody
	@GetMapping("getParam")
	public ResultResponse getParam(String key) {
		return new ResultResponse(true, key);
	}

	@GetMapping("thymeleaf")
	public String thymeleaf(ModelMap model) {
		model.addAttribute("hello", "chenzhf");
		return "hello";
	}
}
